//
//  XHLuckyDrawViewController.m
//  umibus
//
//  Created by 冷山 on 16/6/18.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

#import "XHLuckyDrawViewController.h"
#import "XHIntegralDetailViewController.h"
#import "XHTabBarController.h"

#import "XHLuckViewCell.h"

#import "Services.h"
#import "AppDelegate.h"

#import <UIAlertView+Blocks.h>

@interface XHLuckyDrawViewController ()

@property (weak, nonatomic) IBOutlet UIView *ui_luckView;
@property (weak, nonatomic) IBOutlet UICollectionView *ui_collectionView;
@property (strong, nonatomic) NSArray * m_array;
@property (strong, nonatomic) NSDictionary * m_info;
@property (weak, nonatomic) IBOutlet UILabel *ui_one;
@property (weak, nonatomic) IBOutlet UILabel *ui_two;
@property (weak, nonatomic) IBOutlet UILabel *ui_three;
@property (weak, nonatomic) IBOutlet UILabel *ui_four;
@property (weak, nonatomic) IBOutlet UILabel *ui_five;
@property (weak, nonatomic) IBOutlet UILabel *ui_six;
@property (weak, nonatomic) IBOutlet UILabel *ui_seven;
@property (strong, nonatomic) NSTimer * timer;
@property (strong, nonatomic) NSTimer * timer2;

@property (assign, nonatomic) int seconds;

@end

@implementation XHLuckyDrawViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.ui_collectionView.showsVerticalScrollIndicator =YES;
    self.ui_collectionView.showsHorizontalScrollIndicator = YES;
    self.ui_luckView.layer.masksToBounds = YES;
    self.ui_luckView.layer.cornerRadius = 8;
    UINib * nib = [UINib nibWithNibName:@"XHLuckViewCell" bundle:nil];
    [self.ui_collectionView registerNib:nib forCellWithReuseIdentifier:@"XHLuckViewCell"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self getWinningInfo];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [self.timer invalidate];
}
- (void)getWinningInfo
{
    [ServiceManager getWinningInfoWithSuccess:^(NSDictionary *data) {
        self.m_array = (NSArray*)data;
        [self awardsShow];
        [self.ui_collectionView reloadData];
    } failure:^(NSDictionary *data) {
        
    }];
}

- (void)awardsShow
{
    if ([self.m_array isKindOfClass:[NSArray class]])
    {
        if (self.m_array.count>0)
        {
            NSDictionary * dic = self.m_array[0];
            self.ui_one.text = [NSString stringWithFormat:@"一等奖：%@积分",dic[@"scoreValue"]];
            
            NSDictionary * dic1 = self.m_array[1];
            self.ui_two.text = [NSString stringWithFormat:@"二等奖：%@积分",dic1[@"scoreValue"]];
            
            NSDictionary * dic2 = self.m_array[2];
            self.ui_three.text = [NSString stringWithFormat:@"三等奖：%@积分",dic2[@"scoreValue"]];
            
            NSDictionary * dic3 = self.m_array[3];
            self.ui_four.text = [NSString stringWithFormat:@"四等奖：%@积分",dic3[@"scoreValue"]];
            
            NSDictionary * dic4 = self.m_array[4];
            self.ui_five.text = [NSString stringWithFormat:@"五等奖：%@积分",dic4[@"scoreValue"]];
            
            NSDictionary * dic5 = self.m_array[5];
            self.ui_six.text = [NSString stringWithFormat:@"六等奖：%@积分",dic5[@"scoreValue"]];
            
            NSDictionary * dic6 = self.m_array[6];
            self.ui_seven.text = [NSString stringWithFormat:@"七等奖：%@积分",dic6[@"scoreValue"]];
        }
    }
    else
    {
        self.ui_one.text = [NSString stringWithFormat:@"一等奖：0积分"];
        
        self.ui_two.text = [NSString stringWithFormat:@"二等奖：0积分"];
        
        self.ui_three.text = [NSString stringWithFormat:@"三等奖：0积分"];
        
        self.ui_four.text = [NSString stringWithFormat:@"四等奖：0积分"];
        
        self.ui_five.text = [NSString stringWithFormat:@"五等奖：0积分"];
        
        self.ui_six.text = [NSString stringWithFormat:@"六等奖：0积分"];
        
        self.ui_seven.text = [NSString stringWithFormat:@"七等奖：0积分"];
    }
}

#pragma mark -- UICollectionViewDataSource

//定义分组
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//定义个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    NSUInteger rows = 9;
    
    return rows;
}

//每个 UIcollectionView内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    XHLuckViewCell * cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"XHLuckViewCell" forIndexPath:indexPath];
    if (indexPath.item==0)
    {
        cell.ui_imageView.image = [UIImage imageNamed:@"geren_bg_yidengjiagn"];
        cell.ui_label.hidden = NO;
        cell.ui_label.textColor = [ColorManager colorWithHexString:@"#FE6869"];
        if ([self.m_array isKindOfClass:[NSArray class]])
        {
            if (self.m_array.count!=0)
            {
                NSDictionary * dic = self.m_array[0];
                cell.ui_label.text = [NSString stringWithFormat:@"%@积分",dic[@"scoreValue"]];
                [cell.ui_label setAttributedText:[cell changeLabelWithText:cell.ui_label.text]];
            }
        }
        else
        {
            cell.ui_label.hidden = YES;
        }
    }
    else if (indexPath.item==1)
    {
        cell.ui_imageView.image = [UIImage imageNamed:@"geren_bg_erdengjiang"];
        cell.ui_label.hidden = NO;
        cell.ui_label.textColor = [ColorManager colorWithHexString:@"#664425"];
        if ([self.m_array isKindOfClass:[NSArray class]])
        {
            if (self.m_array.count!=0)
            {
                NSDictionary * dic = self.m_array[1];
                cell.ui_label.text = [NSString stringWithFormat:@"%@积分",dic[@"scoreValue"]];
                [cell.ui_label setAttributedText:[cell changeLabelWithText:cell.ui_label.text]];
            }
        }
        else
        {
            cell.ui_label.hidden = YES;
        }
    }
    else if (indexPath.item==2)
    {
        cell.ui_imageView.image = [UIImage imageNamed:@"geren_bg_sandengjiang"];
        cell.ui_label.hidden = NO;
        cell.ui_points.hidden = NO;
        cell.ui_label.textColor = [ColorManager colorWithHexString:@"#094A3A"];
        cell.ui_points.textColor = [ColorManager colorWithHexString:@"#094A3A"];
        if ([self.m_array isKindOfClass:[NSArray class]])
        {
            if (self.m_array.count!=0)
            {
                NSDictionary * dic = self.m_array[2];
                cell.ui_label.text = [NSString stringWithFormat:@"%@积分",dic[@"scoreValue"]];
                [cell.ui_label setAttributedText:[cell changeLabelWithText:cell.ui_label.text]];
            }
        }
        else
        {
            cell.ui_label.hidden = YES;
            cell.ui_points.hidden = YES;
        }
    }
    else if (indexPath.item==3)
    {
        cell.ui_imageView.image = [UIImage imageNamed:@"geren_bg_xiexie"];
        cell.ui_label.hidden = YES;
        cell.ui_points.hidden = YES;
    }
    else if (indexPath.item==4)
    {
        cell.ui_imageView.image = [UIImage imageNamed:@"geren_bg_choujiang"];
        cell.ui_label.hidden = YES;
        cell.ui_points.hidden = YES;
    }
    else if (indexPath.item==5)
    {
        cell.ui_imageView.image = [UIImage imageNamed:@"geren_bg_sidengjiang"];
        cell.ui_label.hidden = NO;
        cell.ui_points.hidden = NO;
        cell.ui_label.textColor = [ColorManager colorWithHexString:@"#2B578B"];
        cell.ui_points.textColor = [ColorManager colorWithHexString:@"#2B578B"];
        if ([self.m_array isKindOfClass:[NSArray class]])
        {
            if (self.m_array.count!=0)
            {
                NSDictionary * dic = self.m_array[3];
                cell.ui_label.text = [NSString stringWithFormat:@"%@积分",dic[@"scoreValue"]];
                [cell.ui_label setAttributedText:[cell changeLabelWithText:cell.ui_label.text]];
            }
        }
        else
        {
            cell.ui_label.hidden = YES;
            cell.ui_points.hidden = YES;
        }
    }
    else if (indexPath.item==6)
    {
        cell.ui_imageView.image = [UIImage imageNamed:@"geren_bg_qidengjiang"];
        cell.ui_label.hidden = NO;
        cell.ui_points.hidden = NO;
        cell.ui_label.textColor = [ColorManager colorWithHexString:@"#094A3A"];
        cell.ui_points.textColor = [ColorManager colorWithHexString:@"#094A3A"];
        if ([self.m_array isKindOfClass:[NSArray class]])
        {
            if (self.m_array.count!=0)
            {
                NSDictionary * dic = self.m_array[6];
                cell.ui_label.text = [NSString stringWithFormat:@"%@积分",dic[@"scoreValue"]];
                [cell.ui_label setAttributedText:[cell changeLabelWithText:cell.ui_label.text]];
            }
        }
        else
        {
            cell.ui_label.hidden = YES;
            cell.ui_points.hidden = YES;
        }
    }
    else if (indexPath.item==7)
    {
        cell.ui_imageView.image = [UIImage imageNamed:@"geren_bg_liudengjiang"];
        cell.ui_label.hidden = NO;
        cell.ui_points.hidden = NO;
        cell.ui_label.textColor = [ColorManager colorWithHexString:@"#664425"];
        cell.ui_points.textColor = [ColorManager colorWithHexString:@"#664425"];
        if ([self.m_array isKindOfClass:[NSArray class]])
        {
            if (self.m_array.count!=0)
            {
                NSDictionary * dic = self.m_array[5];
                cell.ui_label.text = [NSString stringWithFormat:@"%@积分",dic[@"scoreValue"]];
                [cell.ui_label setAttributedText:[cell changeLabelWithText:cell.ui_label.text]];
            }
        }
        else
        {
            cell.ui_label.hidden = YES;
            cell.ui_points.hidden = YES;
        }
    }
    else if (indexPath.item==8)
    {
        cell.ui_imageView.image = [UIImage imageNamed:@"geren_bg_wudengjiang"];
        cell.ui_label.hidden = NO;
        cell.ui_points.hidden = NO;
        cell.ui_label.textColor = [ColorManager colorWithHexString:@"#DC4344"];
        cell.ui_points.textColor = [ColorManager colorWithHexString:@"#DC4344"];
        if ([self.m_array isKindOfClass:[NSArray class]])
        {
            if (self.m_array.count!=0)
            {
                NSDictionary * dic = self.m_array[4];
                cell.ui_label.text = [NSString stringWithFormat:@"%@积分",dic[@"scoreValue"]];
                [cell.ui_label setAttributedText:[cell changeLabelWithText:cell.ui_label.text]];
            }
        }
        else
        {
            cell.ui_label.hidden = YES;
            cell.ui_points.hidden = YES;
        }
    }

    return cell;
}

//点击事件
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.item==4)
    {
        [self getWinningAction];
    }
}

//宽高
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat screenHeight=[[UIScreen mainScreen] bounds].size.height;
    if(screenHeight>568)
    {
        return CGSizeMake(110,110);
    }
    else
    {
        return CGSizeMake(90,90);
    }
}

//边距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    CGFloat screenHeight=[[UIScreen mainScreen] bounds].size.height;
    if(screenHeight>568)
    {
        return UIEdgeInsetsMake(10, 10, 10, 10);
    }
    else
    {
        return UIEdgeInsetsMake(0, 0, 0, 0);
    }
}


#pragma - mark 抽奖事件

- (void)getWinningAction
{
    self.ui_collectionView.userInteractionEnabled = NO;
    [ServiceManager getWinningResultsWithSuccess:^(NSDictionary *data) {
        self.ui_collectionView.userInteractionEnabled = YES;
        self.m_info = data;
        NSString *str = [NSString stringWithFormat:@"%ld",[self.m_info[@"awardLevel"] integerValue]];
        self.timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(testTimer) userInfo:nil repeats:YES];
        self.timer2 = [NSTimer scheduledTimerWithTimeInterval:3.4f target:self selector:@selector(delayMethod:) userInfo:str repeats:NO];
    } failure:^(NSDictionary *data) {
        self.ui_collectionView.userInteractionEnabled = YES;
    }];
}

- (void)delayMethod:(NSTimer*)timer
{
    if ([[timer userInfo] isEqualToString:@"1"])
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:3 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
    }
    else if ([[timer userInfo] isEqualToString:@"2"])
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:1 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:0 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
        
    }
    else if ([[timer userInfo] isEqualToString:@"3"])
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:2 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:1 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
        
        NSIndexPath * indexPath2 = [NSIndexPath indexPathForItem:0 inSection:0];
        UICollectionViewCell * cell2 = [self.ui_collectionView cellForItemAtIndexPath:indexPath2];
        cell2.layer.masksToBounds = YES;
        cell2.layer.cornerRadius = 3;
        cell2.layer.borderWidth = 4;
        cell2.layer.borderColor = [UIColor clearColor].CGColor;
    }
    else if ([[timer userInfo] isEqualToString:@"4"])
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:5 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:2 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
        
        NSIndexPath * indexPath2 = [NSIndexPath indexPathForItem:0 inSection:0];
        UICollectionViewCell * cell2 = [self.ui_collectionView cellForItemAtIndexPath:indexPath2];
        cell2.layer.masksToBounds = YES;
        cell2.layer.cornerRadius = 3;
        cell2.layer.borderWidth = 4;
        cell2.layer.borderColor = [UIColor clearColor].CGColor;
    }
    else if ([[timer userInfo] isEqualToString:@"5"])
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:8 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:5 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
        
        NSIndexPath * indexPath2 = [NSIndexPath indexPathForItem:0 inSection:0];
        UICollectionViewCell * cell2 = [self.ui_collectionView cellForItemAtIndexPath:indexPath2];
        cell2.layer.masksToBounds = YES;
        cell2.layer.cornerRadius = 3;
        cell2.layer.borderWidth = 4;
        cell2.layer.borderColor = [UIColor clearColor].CGColor;

    }
    else if ([[timer userInfo] isEqualToString:@"6"])
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:7 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:8 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
        
        NSIndexPath * indexPath2 = [NSIndexPath indexPathForItem:0 inSection:0];
        UICollectionViewCell * cell2 = [self.ui_collectionView cellForItemAtIndexPath:indexPath2];
        cell2.layer.masksToBounds = YES;
        cell2.layer.cornerRadius = 3;
        cell2.layer.borderWidth = 4;
        cell2.layer.borderColor = [UIColor clearColor].CGColor;

    }
    else if ([[timer userInfo] isEqualToString:@"7"])
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:6 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:7 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
        
        NSIndexPath * indexPath2 = [NSIndexPath indexPathForItem:0 inSection:0];
        UICollectionViewCell * cell2 = [self.ui_collectionView cellForItemAtIndexPath:indexPath2];
        cell2.layer.masksToBounds = YES;
        cell2.layer.cornerRadius = 3;
        cell2.layer.borderWidth = 4;
        cell2.layer.borderColor = [UIColor clearColor].CGColor;
    }
    else
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:3 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:0 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
    }
    NSString * str = [NSString stringWithFormat:@"恭喜获得%@等奖",self.m_info[@"awardLevel"]];
    NSString *title=[NSString stringWithFormat:@"抽奖结果"];
    RIButtonItem *cancelItem=[RIButtonItem itemWithLabel:@"取消"];
    RIButtonItem *callItem=[RIButtonItem itemWithLabel:@"确认" action:^{
        AppDelegate * delegate = [UIApplication sharedApplication].delegate;
        [delegate.tabBarController integralDetailViewController];
        [self.navigationController popToRootViewControllerAnimated:YES];
        
    }];
    UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:title message:str cancelButtonItem:cancelItem otherButtonItems:callItem, nil];
    [alertView show];
}

- (void)testTimer
{

    for (int i=0; i<=17; i++) {
        
    }
    self.seconds++;
    
    if (self.seconds-1==0||
        self.seconds-1==8)
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:3 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
    }
    else if (self.seconds-1 == 1||
             self.seconds-1 == 9)
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:1 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:0 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
    }

    else if (self.seconds-1 == 2||
             self.seconds-1 == 10)
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:2 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:1 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
    }

    else if (self.seconds-1 == 3||
             self.seconds-1 == 11)
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:5 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:2 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
    }
    else if (self.seconds-1 == 4||
             self.seconds-1 == 12)
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:8 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:5 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
    }
    else if (self.seconds-1 == 5||
             self.seconds-1 == 13)
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:7 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:8 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
    }
    else if (self.seconds-1 == 6||
             self.seconds-1 == 14)
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:6 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:7 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
    }
    else if (self.seconds-1 == 7||
             self.seconds-1 == 15)
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:3 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:6 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
    }
    else if (self.seconds-1 == 8||
             self.seconds-1 == 16)
    {
        NSIndexPath * indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
        UICollectionViewCell * cell = [self.ui_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 3;
        cell.layer.borderWidth = 4;
        cell.layer.borderColor = [ColorManager colorWithHexString:@"#DC4344"].CGColor;
        
        NSIndexPath * indexPath1 = [NSIndexPath indexPathForItem:3 inSection:0];
        UICollectionViewCell * cell1 = [self.ui_collectionView cellForItemAtIndexPath:indexPath1];
        cell1.layer.masksToBounds = YES;
        cell1.layer.cornerRadius = 3;
        cell1.layer.borderWidth = 4;
        cell1.layer.borderColor = [UIColor clearColor].CGColor;
    }
    if(self.seconds==17)
    {
        [self.timer invalidate];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
